/*

*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 1e6+10;
int nt[maxn];
char aim[maxn];
char s[maxn];
int flag[maxn];
void getnt(char *s,int len)
{
	int i = 0;
	int j = -1;
	nt[0] = -1;
	while(i<len)
	{
		if(j==-1||s[i]==s[j])
		{
			nt[++i] = ++j;
		}
		else j = nt[j];
	}
}
int kmp(string s,char *aim,int LA,int LS)
{
	int i = 0;
	int j = 0;
	int fp = 0;
	int fs = 0;
	int fm = 0;
	while(i<LA)
	{
		if(j==-1||aim[i]==s[j])
		{
			i++;
			j++;
		}
		else j = nt[j];
		if(j==LS&&i==LS)
		{
			j = 0;
			fp++;
		}
		else if(j==LS&&i==LA)
		{
			fs++;
			j = 0;
		}
		else if(j==LS&&i-LS>0)
		{
			fm++;
			j = 0;
		}
	}
	if(fp&&fm&&fs) return 1;
	else return 0;
}
int main()
{
	cin>>aim;
	int len = strlen(aim);
	getnt(aim,len);
	for(int i = 0;i<len/3;i++)
	{
		s[i] += aim[i];
	}
	for(int i = len/3;i>=0;i--)
	{
		s[i]='\0';
		int ans = kmp(s,aim,len,i);
		if(ans) 
		{
			cout<<s<<endl;
			return 0;
		}
	}
	puts("Just a legend");
} 
